#include "gtest/gtest.h"
#include <mockcpp/mokc.h>
#include <mockcpp/mockcpp.hpp>

#include <vector>
#include <iostream>

#include "topoinfo_struct.h"
#include "log.h"
#include "checker.h"
#include "virtual_topo.h"
#include "testcase_utils.h"
#include <stdlib.h>

using namespace hccl;

std::vector<string> allReduceAlgName = {
    "AllReduceMeshOneshotLoopExecutor",
    "AllReduceMeshOpbaseBigCountAivExecutor",
    "AllReduceMeshOpbaseLoopExecutor",
    "AllReduceMeshOpbasePipelineExecutor",
    "AllReduceMeshSmallCountExecutor",
    "AllReduceRingExecutor",
};

class AllReduceTest : public testing::Test {
protected:
    static void SetUpTestCase()
    {
        std::cout << "CheckOpSemanticsTest set up." << std::endl;
    }

    static void TearDownTestCase()
    {
        std::cout << "CheckOpSemanticsTest tear down." << std::endl;
    }

    virtual void SetUp()
    {
        const ::testing::TestInfo* const test_info = ::testing::UnitTest::GetInstance()->current_test_info();
        std::string caseName = "analysis_result_" + std::string(test_info->test_case_name()) + "_" + std::string(test_info->name());
        Checker::SetDumpFileName(caseName);
    }

    virtual void TearDown()
    {
        Checker::SetDumpFileName("analysis_result");
        GlobalMockObject::verify();
        // 这边每个case执行完成需要清理所有的环境变量，如果有新增的环境变量，需要在这个函数中进行清理
        ClearHcclEnv();
    }
};

TEST_F(AllReduceTest, allreduce_test)
{
    RankTable_t ranktable;
    RankTable_For_LLT gen;
    TopoMeta topoMeta;
    gen.GenTopoMeta(topoMeta, 1, 2, 4);
    gen.GenRankTable(topoMeta, ranktable);

    setenv("HCCL_DETERMINISTIC", "true", 1);

    TestOpParam testOpParam;
    testOpParam.opType = HcclCMDType::HCCL_CMD_ALLREDUCE;
    testOpParam.tag = "AllReduce";
    testOpParam.opMode = OPBASE;
    testOpParam.reduceType = HcclReduceOp::HCCL_REDUCE_SUM;
    testOpParam.devtype = DevType::DEV_TYPE_910B;
    testOpParam.DataDes.count = 800;
    testOpParam.DataDes.dataType = HcclDataType::HCCL_DATA_TYPE_INT32;

    Checker checker;
    HcclResult ret;
    ret = checker.Check(testOpParam, ranktable, topoMeta);

    EXPECT_EQ(ret, HcclResult::HCCL_SUCCESS);
}

TEST_F(AllReduceTest, allreduce_test_loop)
{
    RankTable_For_LLT gen;
    TestOpParam testOpParam;
    testOpParam.opType = HcclCMDType::HCCL_CMD_ALLREDUCE;
    testOpParam.tag = "AllReduce";
    testOpParam.opMode = OPBASE;
    testOpParam.reduceType = HcclReduceOp::HCCL_REDUCE_SUM;
    testOpParam.devtype = DevType::DEV_TYPE_910B;
    testOpParam.DataDes.count = 100;
    testOpParam.DataDes.dataType = HcclDataType::HCCL_DATA_TYPE_INT32;
    setenv("HCCL_DETERMINISTIC", "true", 1);

    HcclResult ret;
    for (int i = 1; i <= 2; i++) {
        for (int j = 1; j <= 8; j++) {
            Checker checker;
            RankTable_t ranktable;
            TopoMeta topoMeta;
            gen.GenTopoMeta(topoMeta, 1, i, j);
            gen.GenRankTable(topoMeta, ranktable);
            ret = checker.Check(testOpParam, ranktable, topoMeta);
            printf("serverNum = %d, rankNum = %d, ret is %d\n", i, j, ret);
            EXPECT_EQ(ret, HcclResult::HCCL_SUCCESS);
        }
    }
}

TEST_F(AllReduceTest, allreduce_test_offload_loop)
{
    RankTable_For_LLT gen;
    TestOpParam testOpParam;
    testOpParam.opType = HcclCMDType::HCCL_CMD_ALLREDUCE;
    testOpParam.tag = "AllReduce";
    testOpParam.opMode = OFFLOAD;
    testOpParam.reduceType = HcclReduceOp::HCCL_REDUCE_SUM;
    testOpParam.devtype = DevType::DEV_TYPE_910B;
    testOpParam.DataDes.count = 100;
    testOpParam.DataDes.dataType = HcclDataType::HCCL_DATA_TYPE_INT32;
    setenv("HCCL_DETERMINISTIC", "true", 1);
    HcclResult ret;
    for (int i = 1; i <= 2; i++) {
        for (int j = 1; j <= 8; j++) {
            Checker checker;
            RankTable_t ranktable;
            TopoMeta topoMeta;
            gen.GenTopoMeta(topoMeta, 1, i, j);
            gen.GenRankTable(topoMeta, ranktable);
            ret = checker.Check(testOpParam, ranktable, topoMeta);
            EXPECT_EQ(ret, HcclResult::HCCL_SUCCESS);
        }
    }
}

TEST_F(AllReduceTest, allreduce_executor_offload_AllReduceMeshOneshotLoopExecutor)
{
    RankTable_t ranktable;
    RankTable_For_LLT gen;
    TopoMeta topoMeta;
    gen.GenTopoMeta(topoMeta, 1, 1, 8);
    gen.GenRankTable(topoMeta, ranktable);

    TestOpParam testOpParam;
    testOpParam.opType = HcclCMDType::HCCL_CMD_ALLREDUCE;
    testOpParam.tag = "AllReduce";
    testOpParam.opMode = OFFLOAD;
    testOpParam.reduceType = HcclReduceOp::HCCL_REDUCE_SUM;
    testOpParam.devtype = DevType::DEV_TYPE_910B;
    testOpParam.DataDes.count = 800;
    testOpParam.DataDes.dataType = HcclDataType::HCCL_DATA_TYPE_INT32;
    testOpParam.algName = "AllReduceMeshOneshotLoopExecutor";
    Checker checker;
    HcclResult ret;
    ret = checker.Check(testOpParam, ranktable, topoMeta);
    EXPECT_EQ(ret, HcclResult::HCCL_SUCCESS);
}

TEST_F(AllReduceTest, allreduce_executor_offload_AllReduceMeshSmallCountExecutor)
{
    RankTable_t ranktable;
    RankTable_For_LLT gen;
    TopoMeta topoMeta;
    gen.GenTopoMeta(topoMeta, 1, 1, 8);
    gen.GenRankTable(topoMeta, ranktable);
    setenv("HCCL_DETERMINISTIC", "true", 1);
    TestOpParam testOpParam;
    testOpParam.opType = HcclCMDType::HCCL_CMD_ALLREDUCE;
    testOpParam.tag = "AllReduce";
    testOpParam.opMode = OFFLOAD;
    testOpParam.reduceType = HcclReduceOp::HCCL_REDUCE_SUM;
    testOpParam.devtype = DevType::DEV_TYPE_910B;
    testOpParam.DataDes.count = 800;
    testOpParam.DataDes.dataType = HcclDataType::HCCL_DATA_TYPE_INT32;
    testOpParam.algName = "AllReduceMeshSmallCountExecutor";
    Checker checker;
    HcclResult ret;
    ret = checker.Check(testOpParam, ranktable, topoMeta);
    EXPECT_EQ(ret, HcclResult::HCCL_SUCCESS);
}

// 跑AllReduceReduceBcast
TEST_F(AllReduceTest, allreduce_AllReduceReduceBcast)
{
    RankTable_t ranktable;
    RankTable_For_LLT gen;
    TopoMeta topoMeta;
    gen.GenTopoMeta(topoMeta, 1, 1, 8);
    gen.GenRankTable(topoMeta, ranktable);

    setenv("HCCL_DETERMINISTIC", "false", 1);

    TestOpParam testOpParam;
    testOpParam.opType = HcclCMDType::HCCL_CMD_ALLREDUCE;
    testOpParam.tag = "AllReduce";
    testOpParam.opMode = OFFLOAD;
    testOpParam.reduceType = HcclReduceOp::HCCL_REDUCE_SUM;
    testOpParam.devtype = DevType::DEV_TYPE_910B;
    testOpParam.DataDes.count = 100;
    testOpParam.DataDes.dataType = HcclDataType::HCCL_DATA_TYPE_INT8;
    testOpParam.algName = "AllReduceMeshSmallCountExecutor";

    Checker checker;
    HcclResult ret;
    checker.CloseRankMemCheck();    // AllReduceReduceBcast算法以mesh方式做原子Reduce操作，导致内存冲突检测误报
    ret = checker.Check(testOpParam, ranktable, topoMeta);
    EXPECT_EQ(ret, HcclResult::HCCL_SUCCESS);
}

TEST_F(AllReduceTest, allreduce_executor_offload_AllReduceRingExecutor)
{
    RankTable_t ranktable;
    RankTable_For_LLT gen;
    TopoMeta topoMeta;
    gen.GenTopoMeta(topoMeta, 1, 1, 8);
    gen.GenRankTable(topoMeta, ranktable);

    TestOpParam testOpParam;
    testOpParam.opType = HcclCMDType::HCCL_CMD_ALLREDUCE;
    testOpParam.tag = "AllReduce";
    testOpParam.opMode = OFFLOAD;
    testOpParam.reduceType = HcclReduceOp::HCCL_REDUCE_SUM;
    testOpParam.devtype = DevType::DEV_TYPE_910B;
    testOpParam.DataDes.count = 800;
    testOpParam.DataDes.dataType = HcclDataType::HCCL_DATA_TYPE_INT32;
    testOpParam.algName = "AllReduceRingExecutor";
    Checker checker;
    HcclResult ret;
    ret = checker.Check(testOpParam, ranktable, topoMeta);
    EXPECT_EQ(ret, HcclResult::HCCL_SUCCESS);
}

TEST_F(AllReduceTest, allreduce_allReduceComm_executor_test)
{
    RankTable_t ranktable;
    RankTable_For_LLT gen;
    TopoMeta topoMeta;
    gen.GenTopoMeta(topoMeta, 1, 1, 8);
    gen.GenRankTable(topoMeta, ranktable);

    TestOpParam testOpParam;
    testOpParam.opType = HcclCMDType::HCCL_CMD_ALLREDUCE;
    testOpParam.tag = "AllReduce";
    testOpParam.algName = "AllReduceComm";
    testOpParam.opMode = OPBASE;
    testOpParam.reduceType = HcclReduceOp::HCCL_REDUCE_SUM;
    testOpParam.devtype = DevType::DEV_TYPE_910B;
    testOpParam.DataDes.count = 100;
    testOpParam.DataDes.dataType = HcclDataType::HCCL_DATA_TYPE_INT32;

    Checker checker;
    HcclResult ret;
    ret = checker.Check(testOpParam, ranktable, topoMeta);

    EXPECT_EQ(ret, HcclResult::HCCL_SUCCESS);
}

TEST_F(AllReduceTest, allreduce_executor_test_loop)
{
    RankTable_t ranktable;
    RankTable_For_LLT gen;
    TopoMeta topoMeta;
    gen.GenTopoMeta(topoMeta, 1, 1, 8);
    gen.GenRankTable(topoMeta, ranktable);

    TestOpParam testOpParam;
    testOpParam.opType = HcclCMDType::HCCL_CMD_ALLREDUCE;
    testOpParam.tag = "AllReduce";
    testOpParam.opMode = OPBASE;
    testOpParam.reduceType = HcclReduceOp::HCCL_REDUCE_SUM;
    testOpParam.devtype = DevType::DEV_TYPE_910B;
    testOpParam.DataDes.count = 800;
    testOpParam.DataDes.dataType = HcclDataType::HCCL_DATA_TYPE_INT32;

    for (int i = 0; i < allReduceAlgName.size(); i++) {
        testOpParam.algName = allReduceAlgName[i];
        Checker checker;
        HcclResult ret;
        checker.CloseRankMemCheck();
        ret = checker.Check(testOpParam, ranktable, topoMeta);
        if (ret == HcclResult::HCCL_SUCCESS) {
            std::cout << allReduceAlgName[i] + " run successed" << std::endl;
        } else {
            std::cout << allReduceAlgName[i] + " run failed" << std::endl;
        }
        EXPECT_EQ(ret, HcclResult::HCCL_SUCCESS);
    }
}

TEST_F(AllReduceTest, allreduce_AllReduceMeshMidCountLoopExecutor_test)
{
    RankTable_t ranktable;
    RankTable_For_LLT gen;
    TopoMeta topoMeta;
    gen.GenTopoMeta(topoMeta, 1, 1, 8);
    gen.GenRankTable(topoMeta, ranktable);

    TestOpParam testOpParam;
    testOpParam.opType = HcclCMDType::HCCL_CMD_ALLREDUCE;
    testOpParam.tag = "AllReduce";
    testOpParam.algName = "AllReduceMeshMidCountLoopExecutor";
    testOpParam.opMode = OPBASE;
    testOpParam.reduceType = HcclReduceOp::HCCL_REDUCE_SUM;
    testOpParam.devtype = DevType::DEV_TYPE_910B;
    testOpParam.DataDes.count = 800;
    testOpParam.DataDes.dataType = HcclDataType::HCCL_DATA_TYPE_INT32;

    Checker checker;
    HcclResult ret;
    ret = checker.Check(testOpParam, ranktable, topoMeta);

    EXPECT_EQ(ret, HcclResult::HCCL_SUCCESS);
}

TEST_F(AllReduceTest, allreduce_AllReduceSingleExecutor_test)
{
    RankTable_t ranktable;
    RankTable_For_LLT gen;
    TopoMeta topoMeta;
    gen.GenTopoMeta(topoMeta, 1, 1, 1);
    gen.GenRankTable(topoMeta, ranktable);

    TestOpParam testOpParam;
    testOpParam.opType = HcclCMDType::HCCL_CMD_ALLREDUCE;
    testOpParam.tag = "AllReduce";
    testOpParam.algName = "AllReduceSingleExecutor";
    testOpParam.opMode = OPBASE;
    testOpParam.reduceType = HcclReduceOp::HCCL_REDUCE_SUM;
    testOpParam.devtype = DevType::DEV_TYPE_910B;
    testOpParam.DataDes.count = 100;
    testOpParam.DataDes.dataType = HcclDataType::HCCL_DATA_TYPE_INT32;

    Checker checker;
    HcclResult ret;
    ret = checker.Check(testOpParam, ranktable, topoMeta);

    EXPECT_EQ(ret, HcclResult::HCCL_SUCCESS);
}

TEST_F(AllReduceTest, allreduce_910A_offload_AllReduceMeshExecutor)
{
    RankTable_t ranktable;
    RankTable_For_LLT gen;
    TopoMeta topoMeta;
    gen.GenTopoMeta(topoMeta, 1, 1, 4);  // 等下改成8，看看会不会报错
    gen.GenRankTable(topoMeta, ranktable);

    TestOpParam testOpParam;
    testOpParam.opType = HcclCMDType::HCCL_CMD_ALLREDUCE;
    testOpParam.tag = "AllReduce";
    testOpParam.opMode = OFFLOAD;
    testOpParam.reduceType = HcclReduceOp::HCCL_REDUCE_SUM;
    testOpParam.devtype = DevType::DEV_TYPE_910;
    testOpParam.DataDes.count = 800;
    testOpParam.DataDes.dataType = HcclDataType::HCCL_DATA_TYPE_INT32;
    testOpParam.algName = "AllReduceMeshExecutor";
    Checker checker;
    HcclResult ret;
    ret = checker.Check(testOpParam, ranktable, topoMeta);
    EXPECT_EQ(ret, HcclResult::HCCL_SUCCESS);
}

TEST_F(AllReduceTest, allreduce_910A_offload_AllReduceRingExecutor)
{
    RankTable_t ranktable;
    RankTable_For_LLT gen;
    TopoMeta topoMeta;
    gen.GenTopoMeta(topoMeta, 1, 2, 8);
    gen.GenRankTable(topoMeta, ranktable);

    TestOpParam testOpParam;
    testOpParam.opType = HcclCMDType::HCCL_CMD_ALLREDUCE;
    testOpParam.tag = "AllReduce";
    testOpParam.opMode = OFFLOAD;
    testOpParam.reduceType = HcclReduceOp::HCCL_REDUCE_SUM;
    testOpParam.devtype = DevType::DEV_TYPE_910;
    testOpParam.DataDes.count = 800;
    testOpParam.DataDes.dataType = HcclDataType::HCCL_DATA_TYPE_INT32;
    testOpParam.algName = "AllReduceRingExecutor";
    Checker checker;
    HcclResult ret;
    ret = checker.Check(testOpParam, ranktable, topoMeta);
    EXPECT_EQ(ret, HcclResult::HCCL_SUCCESS);
}

TEST_F(AllReduceTest, allreduce_910A_offload_AllReduceComm)
{
    RankTable_t ranktable;
    RankTable_For_LLT gen;
    TopoMeta topoMeta {{{2, 5}, {0, 1, 2}}};
    gen.GenRankTable(topoMeta, ranktable);

    TestOpParam testOpParam;
    testOpParam.opType = HcclCMDType::HCCL_CMD_ALLREDUCE;
    testOpParam.tag = "AllReduce";
    testOpParam.opMode = OFFLOAD;
    testOpParam.reduceType = HcclReduceOp::HCCL_REDUCE_SUM;
    testOpParam.devtype = DevType::DEV_TYPE_910;
    testOpParam.DataDes.count = 800;
    testOpParam.DataDes.dataType = HcclDataType::HCCL_DATA_TYPE_INT32;
    testOpParam.algName = "AllReduceComm";
    Checker checker;
    HcclResult ret;
    ret = checker.Check(testOpParam, ranktable, topoMeta);
    EXPECT_EQ(ret, HcclResult::HCCL_SUCCESS);
}

TEST_F(AllReduceTest, allreduce_910A_opbase_AllReduceMeshExecutor)
{
    RankTable_t ranktable;
    RankTable_For_LLT gen;
    TopoMeta topoMeta;
    gen.GenTopoMeta(topoMeta, 1, 1, 4);
    gen.GenRankTable(topoMeta, ranktable);

    TestOpParam testOpParam;
    testOpParam.opType = HcclCMDType::HCCL_CMD_ALLREDUCE;
    testOpParam.tag = "AllReduce";
    testOpParam.opMode = OPBASE;
    testOpParam.reduceType = HcclReduceOp::HCCL_REDUCE_SUM;
    testOpParam.devtype = DevType::DEV_TYPE_910;
    testOpParam.DataDes.count = 800;
    testOpParam.DataDes.dataType = HcclDataType::HCCL_DATA_TYPE_INT32;
    testOpParam.algName = "AllReduceMeshExecutor";
    Checker checker;
    HcclResult ret;
    ret = checker.Check(testOpParam, ranktable, topoMeta);
    EXPECT_EQ(ret, HcclResult::HCCL_SUCCESS);
}

TEST_F(AllReduceTest, allreduce_910A_opbase_AllReduceRingExecutor)
{
    RankTable_t ranktable;
    RankTable_For_LLT gen;
    TopoMeta topoMeta;
    gen.GenTopoMeta(topoMeta, 1, 2, 8);
    gen.GenRankTable(topoMeta, ranktable);

    TestOpParam testOpParam;
    testOpParam.opType = HcclCMDType::HCCL_CMD_ALLREDUCE;
    testOpParam.tag = "AllReduce";
    testOpParam.opMode = OPBASE;
    testOpParam.reduceType = HcclReduceOp::HCCL_REDUCE_SUM;
    testOpParam.devtype = DevType::DEV_TYPE_910;
    testOpParam.DataDes.count = 800;
    testOpParam.DataDes.dataType = HcclDataType::HCCL_DATA_TYPE_INT32;
    testOpParam.algName = "AllReduceRingExecutor";
    Checker checker;
    HcclResult ret;
    ret = checker.Check(testOpParam, ranktable, topoMeta);
    EXPECT_EQ(ret, HcclResult::HCCL_SUCCESS);
}

TEST_F(AllReduceTest, allreduce_910A_opbase_AllReduceComm)
{
    RankTable_t ranktable;
    RankTable_For_LLT gen;
    TopoMeta topoMeta {{{2, 5}, {0, 1, 2}}};
    gen.GenRankTable(topoMeta, ranktable);

    TestOpParam testOpParam;
    testOpParam.opType = HcclCMDType::HCCL_CMD_ALLREDUCE;
    testOpParam.tag = "AllReduce";
    testOpParam.opMode = OPBASE;
    testOpParam.reduceType = HcclReduceOp::HCCL_REDUCE_SUM;
    testOpParam.devtype = DevType::DEV_TYPE_910;
    testOpParam.DataDes.count = 800;
    testOpParam.DataDes.dataType = HcclDataType::HCCL_DATA_TYPE_INT32;
    testOpParam.algName = "AllReduceComm";
    Checker checker;
    HcclResult ret;
    ret = checker.Check(testOpParam, ranktable, topoMeta);
    EXPECT_EQ(ret, HcclResult::HCCL_SUCCESS);
}

TEST_F(AllReduceTest, allreduce_910_93_opbase_AllReduceFastDoubleRingFor91093Executor)
{
    RankTable_t ranktable;
    RankTable_For_LLT gen;
    TopoMeta topoMeta;
    gen.GenTopoMeta(topoMeta, 1, 1, 4);
    gen.GenRankTable(topoMeta, ranktable);

    TestOpParam testOpParam;
    testOpParam.opType = HcclCMDType::HCCL_CMD_ALLREDUCE;
    testOpParam.tag = "AllReduce";
    testOpParam.opMode = OPBASE;
    testOpParam.reduceType = HcclReduceOp::HCCL_REDUCE_SUM;
    testOpParam.devtype = DevType::DEV_TYPE_910_93;
    testOpParam.DataDes.count = 800;
    testOpParam.DataDes.dataType = HcclDataType::HCCL_DATA_TYPE_INT32;
    testOpParam.algName = "AllReduceFastDoubleRingFor91093Executor";
    Checker checker;
    HcclResult ret;
    ret = checker.Check(testOpParam, ranktable, topoMeta);
    EXPECT_EQ(ret, HcclResult::HCCL_SUCCESS);
}

TEST_F(AllReduceTest, allreduce_910_93_offload_AllReduceFastDoubleRingFor91093Executor)
{
    RankTable_t ranktable;
    RankTable_For_LLT gen;
    TopoMeta topoMeta;
    gen.GenTopoMeta(topoMeta, 1, 1, 4);
    gen.GenRankTable(topoMeta, ranktable);

    TestOpParam testOpParam;
    testOpParam.opType = HcclCMDType::HCCL_CMD_ALLREDUCE;
    testOpParam.tag = "AllReduce";
    testOpParam.opMode = OFFLOAD;
    testOpParam.reduceType = HcclReduceOp::HCCL_REDUCE_SUM;
    testOpParam.devtype = DevType::DEV_TYPE_910_93;
    testOpParam.DataDes.count = 800;
    testOpParam.DataDes.dataType = HcclDataType::HCCL_DATA_TYPE_INT32;
    testOpParam.algName = "AllReduceFastDoubleRingFor91093Executor";
    Checker checker;
    HcclResult ret;
    ret = checker.Check(testOpParam, ranktable, topoMeta);
    EXPECT_EQ(ret, HcclResult::HCCL_SUCCESS);
}

TEST_F(AllReduceTest, allreduce_910_93_opbase_AlignedAllReduceDoubleRingFor91093Executor)
{
    RankTable_t ranktable;
    RankTable_For_LLT gen;
    TopoMeta topoMeta;
    gen.GenTopoMeta(topoMeta, 1, 1, 8);
    gen.GenRankTable(topoMeta, ranktable);

    TestOpParam testOpParam;
    testOpParam.opType = HcclCMDType::HCCL_CMD_ALLREDUCE;
    testOpParam.tag = "AllReduce";
    testOpParam.opMode = OPBASE;
    testOpParam.reduceType = HcclReduceOp::HCCL_REDUCE_SUM;
    testOpParam.devtype = DevType::DEV_TYPE_910_93;
    testOpParam.DataDes.count = 800;
    testOpParam.DataDes.dataType = HcclDataType::HCCL_DATA_TYPE_INT32;
    testOpParam.algName = "AlignedAllReduceDoubleRingFor91093Executor";
    Checker checker;
    HcclResult ret;
    ret = checker.Check(testOpParam, ranktable, topoMeta);
    EXPECT_EQ(ret, HcclResult::HCCL_SUCCESS);
}

TEST_F(AllReduceTest, allreduce_910_93_offload_AlignedAllReduceDoubleRingFor91093Executor)
{
    RankTable_t ranktable;
    RankTable_For_LLT gen;
    TopoMeta topoMeta;
    gen.GenTopoMeta(topoMeta, 1, 1, 4);
    gen.GenRankTable(topoMeta, ranktable);

    TestOpParam testOpParam;
    testOpParam.opType = HcclCMDType::HCCL_CMD_ALLREDUCE;
    testOpParam.tag = "AllReduce";
    testOpParam.opMode = OFFLOAD;
    testOpParam.reduceType = HcclReduceOp::HCCL_REDUCE_SUM;
    testOpParam.devtype = DevType::DEV_TYPE_910_93;
    testOpParam.DataDes.count = 800;
    testOpParam.DataDes.dataType = HcclDataType::HCCL_DATA_TYPE_INT32;
    testOpParam.algName = "AlignedAllReduceDoubleRingFor91093Executor";
    Checker checker;
    HcclResult ret;
    ret = checker.Check(testOpParam, ranktable, topoMeta);
    EXPECT_EQ(ret, HcclResult::HCCL_SUCCESS);
}

TEST_F(AllReduceTest, allreduce_910_93_opbase_AllReduceRingFor91093Executor)
{
    RankTable_t ranktable;
    RankTable_For_LLT gen;
    TopoMeta topoMeta;
    gen.GenTopoMeta(topoMeta, 1, 1, 8);
    gen.GenRankTable(topoMeta, ranktable);

    TestOpParam testOpParam;
    testOpParam.opType = HcclCMDType::HCCL_CMD_ALLREDUCE;
    testOpParam.tag = "AllReduce";
    testOpParam.opMode = OPBASE;
    testOpParam.reduceType = HcclReduceOp::HCCL_REDUCE_SUM;
    testOpParam.devtype = DevType::DEV_TYPE_910_93;
    testOpParam.DataDes.count = 800;
    testOpParam.DataDes.dataType = HcclDataType::HCCL_DATA_TYPE_INT32;
    testOpParam.algName = "AllReduceRingFor91093Executor";
    Checker checker;
    HcclResult ret;
    ret = checker.Check(testOpParam, ranktable, topoMeta);
    EXPECT_EQ(ret, HcclResult::HCCL_SUCCESS);
}

TEST_F(AllReduceTest, allreduce_910_93_opbase_NHRoneshot)
{
    RankTable_t ranktable;
    RankTable_For_LLT gen;
    TopoMeta topoMeta;
    gen.GenTopoMeta(topoMeta, 1, 2, 4);
    gen.GenRankTable(topoMeta, ranktable);
    setenv("HCCL_ALGO", "level0:ring;level1:NHR", 1);

    TestOpParam testOpParam;
    testOpParam.opType = HcclCMDType::HCCL_CMD_ALLREDUCE;
    testOpParam.tag = "AllReduce";
    testOpParam.opMode = OPBASE;
    testOpParam.reduceType = HcclReduceOp::HCCL_REDUCE_SUM;
    testOpParam.devtype = DevType::DEV_TYPE_910_93;
    testOpParam.DataDes.count = 800;
    testOpParam.DataDes.dataType = HcclDataType::HCCL_DATA_TYPE_INT64;
    testOpParam.algName = "AllReduceFastDoubleRingFor91093Executor";
    Checker checker;
    HcclResult ret;
    checker.EnableGraphicDump();
    ret = checker.Check(testOpParam, ranktable, topoMeta);
    EXPECT_EQ(ret, HcclResult::HCCL_SUCCESS);
}

TEST_F(AllReduceTest, allreduce_910_93_opbase_NHRoneshot_reduce_min)
{
    RankTable_t ranktable;
    RankTable_For_LLT gen;
    TopoMeta topoMeta;
    gen.GenTopoMeta(topoMeta, 1, 2, 4);
    gen.GenRankTable(topoMeta, ranktable);
    setenv("HCCL_ALGO", "level0:ring;level1:NHR", 1);

    TestOpParam testOpParam;
    testOpParam.opType = HcclCMDType::HCCL_CMD_ALLREDUCE;
    testOpParam.tag = "AllReduce";
    testOpParam.opMode = OPBASE;
    testOpParam.reduceType = HcclReduceOp::HCCL_REDUCE_MIN;
    testOpParam.devtype = DevType::DEV_TYPE_910_93;
    testOpParam.DataDes.count = 800;
    testOpParam.DataDes.dataType = HcclDataType::HCCL_DATA_TYPE_INT64;
    testOpParam.algName = "AllReduceFastDoubleRingFor91093Executor";
    Checker checker;
    HcclResult ret;
    checker.EnableGraphicDump();
    ret = checker.Check(testOpParam, ranktable, topoMeta);
    EXPECT_EQ(ret, HcclResult::HCCL_SUCCESS);
}

TEST_F(AllReduceTest, allreduce_910_93_opbase_NHRoneshot_reduce_max)
{
    RankTable_t ranktable;
    RankTable_For_LLT gen;
    TopoMeta topoMeta;
    gen.GenTopoMeta(topoMeta, 1, 2, 4);
    gen.GenRankTable(topoMeta, ranktable);
    setenv("HCCL_ALGO", "level0:ring;level1:NHR", 1);

    TestOpParam testOpParam;
    testOpParam.opType = HcclCMDType::HCCL_CMD_ALLREDUCE;
    testOpParam.tag = "AllReduce";
    testOpParam.opMode = OPBASE;
    testOpParam.reduceType = HcclReduceOp::HCCL_REDUCE_MAX;
    testOpParam.devtype = DevType::DEV_TYPE_910_93;
    testOpParam.DataDes.count = 800;
    testOpParam.DataDes.dataType = HcclDataType::HCCL_DATA_TYPE_INT64;
    testOpParam.algName = "AllReduceFastDoubleRingFor91093Executor";
    Checker checker;
    HcclResult ret;
    checker.EnableGraphicDump();
    ret = checker.Check(testOpParam, ranktable, topoMeta);
    EXPECT_EQ(ret, HcclResult::HCCL_SUCCESS);
}

TEST_F(AllReduceTest, allreduce_910_93_opbase_NHRoneshot_reduce_prod)
{
    RankTable_t ranktable;
    RankTable_For_LLT gen;
    TopoMeta topoMeta;
    gen.GenTopoMeta(topoMeta, 1, 2, 4);
    gen.GenRankTable(topoMeta, ranktable);
    setenv("HCCL_ALGO", "level0:ring;level1:NHR", 1);

    TestOpParam testOpParam;
    testOpParam.opType = HcclCMDType::HCCL_CMD_ALLREDUCE;
    testOpParam.tag = "AllReduce";
    testOpParam.opMode = OPBASE;
    testOpParam.reduceType = HcclReduceOp::HCCL_REDUCE_PROD;
    testOpParam.devtype = DevType::DEV_TYPE_910_93;
    testOpParam.DataDes.count = 800;
    testOpParam.DataDes.dataType = HcclDataType::HCCL_DATA_TYPE_INT64;
    testOpParam.algName = "AllReduceFastDoubleRingFor91093Executor";
    Checker checker;
    HcclResult ret;
    checker.EnableGraphicDump();
    ret = checker.Check(testOpParam, ranktable, topoMeta);
    EXPECT_EQ(ret, HcclResult::HCCL_SUCCESS);
}

TEST_F(AllReduceTest, allreduce_910_93_AllReduceRingFor91093Executor_NHR_tbe)
{
    RankTable_t ranktable;
    RankTable_For_LLT gen;
    TopoMeta topoMeta;
    gen.GenTopoMeta(topoMeta, 1, 4, 8);
    gen.GenRankTable(topoMeta, ranktable);
    setenv("HCCL_ALGO", "level0:ring;level1:NHR", 1);

    TestOpParam testOpParam;
    testOpParam.opType = HcclCMDType::HCCL_CMD_ALLREDUCE;
    testOpParam.tag = "AllReduce";
    testOpParam.opMode = OPBASE;
    testOpParam.reduceType = HcclReduceOp::HCCL_REDUCE_SUM;
    testOpParam.devtype = DevType::DEV_TYPE_910_93;
    testOpParam.DataDes.count = 4*1024*1024;
    testOpParam.DataDes.dataType = HcclDataType::HCCL_DATA_TYPE_INT64;
    testOpParam.algName = "AllReduceFastDoubleRingFor91093Executor";
    Checker checker;
    HcclResult ret;
    ret = checker.Check(testOpParam, ranktable, topoMeta);
    EXPECT_EQ(ret, HcclResult::HCCL_SUCCESS);
}

TEST_F(AllReduceTest, allreduce_910_93_AllReduceRingFor91093Executor_NHR)
{
    RankTable_t ranktable;
    RankTable_For_LLT gen;
    TopoMeta topoMeta;
    gen.GenTopoMeta(topoMeta, 1, 2, 8);
    gen.GenRankTable(topoMeta, ranktable);
    setenv("HCCL_ALGO", "level0:ring;level1:NHR", 1);

    TestOpParam testOpParam;
    testOpParam.opType = HcclCMDType::HCCL_CMD_ALLREDUCE;
    testOpParam.tag = "AllReduce";
    testOpParam.opMode = OPBASE;
    testOpParam.reduceType = HcclReduceOp::HCCL_REDUCE_SUM;
    testOpParam.devtype = DevType::DEV_TYPE_910_93;
    testOpParam.DataDes.count = 4*1024*1024;
    testOpParam.DataDes.dataType = HcclDataType::HCCL_DATA_TYPE_FP32;
    testOpParam.algName = "AllReduceRingFor91093Executor";
    Checker checker;
    HcclResult ret;
    ret = checker.Check(testOpParam, ranktable, topoMeta);
    EXPECT_EQ(ret, HcclResult::HCCL_SUCCESS);
}

// 存在stream越界问题，需要对应的算法进行定位
#if 0
TEST_F(AllReduceTest, allreduce_910_93_offload_AllReduceRingFor91093Executor)
{
    RankTable_t ranktable;
    RankTable_For_LLT gen;
    TopoMeta topoMeta;
    gen.GenTopoMeta(topoMeta, 1, 1, 4);
    gen.GenRankTable(topoMeta, ranktable);

    TestOpParam testOpParam;
    testOpParam.opType = HcclCMDType::HCCL_CMD_ALLREDUCE;
    testOpParam.tag = "AllReduce";
    testOpParam.opMode = OFFLOAD;
    testOpParam.reduceType = HcclReduceOp::HCCL_REDUCE_SUM;
    testOpParam.devtype = DevType::DEV_TYPE_910_93;
    testOpParam.DataDes.count = 800;
    testOpParam.DataDes.dataType = HcclDataType::HCCL_DATA_TYPE_INT32;
    testOpParam.algName = "AllReduceRingFor91093Executor";
    Checker checker;
    HcclResult ret;
    ret = checker.Check(testOpParam, ranktable, topoMeta);
    EXPECT_EQ(ret, HcclResult::HCCL_SUCCESS);
}
#endif

TEST_F(AllReduceTest, allreduce_910_93_opbase_AllReduceComm)
{
    RankTable_t ranktable;
    RankTable_For_LLT gen;
    TopoMeta topoMeta;
    gen.GenTopoMeta(topoMeta, 1, 1, 8);
    gen.GenRankTable(topoMeta, ranktable);

    TestOpParam testOpParam;
    testOpParam.opType = HcclCMDType::HCCL_CMD_ALLREDUCE;
    testOpParam.tag = "AllReduce";
    testOpParam.opMode = OPBASE;
    testOpParam.reduceType = HcclReduceOp::HCCL_REDUCE_SUM;
    testOpParam.devtype = DevType::DEV_TYPE_910_93;
    testOpParam.DataDes.count = 800;
    testOpParam.DataDes.dataType = HcclDataType::HCCL_DATA_TYPE_INT32;
    testOpParam.algName = "AllReduceComm";
    Checker checker;
    HcclResult ret;
    ret = checker.Check(testOpParam, ranktable, topoMeta);
    EXPECT_EQ(ret, HcclResult::HCCL_SUCCESS);
}

TEST_F(AllReduceTest, allreduce_910_93_offload_AllReduceComm)
{
    RankTable_t ranktable;
    RankTable_For_LLT gen;
    TopoMeta topoMeta;
    gen.GenTopoMeta(topoMeta, 1, 1, 4);
    gen.GenRankTable(topoMeta, ranktable);

    TestOpParam testOpParam;
    testOpParam.opType = HcclCMDType::HCCL_CMD_ALLREDUCE;
    testOpParam.tag = "AllReduce";
    testOpParam.opMode = OFFLOAD;
    testOpParam.reduceType = HcclReduceOp::HCCL_REDUCE_SUM;
    testOpParam.devtype = DevType::DEV_TYPE_910_93;
    testOpParam.DataDes.count = 800;
    testOpParam.DataDes.dataType = HcclDataType::HCCL_DATA_TYPE_INT32;
    testOpParam.algName = "AllReduceComm";
    Checker checker;
    HcclResult ret;
    ret = checker.Check(testOpParam, ranktable, topoMeta);
    EXPECT_EQ(ret, HcclResult::HCCL_SUCCESS);
}

TEST_F(AllReduceTest, allreduce_910_93_offload_AllReduceDoubleRingConcurrentExecutor)
{
    RankTable_t ranktable;
    RankTable_For_LLT gen;
    TopoMeta topoMeta;
    gen.GenTopoMeta(topoMeta, 1, 1, 4);
    gen.GenRankTable(topoMeta, ranktable);

    setenv("HCCL_CONCURRENT_ENABLE", "1", 1);

    TestOpParam testOpParam;
    testOpParam.opType = HcclCMDType::HCCL_CMD_ALLREDUCE;
    testOpParam.tag = "AllReduce";
    testOpParam.opMode = OFFLOAD;
    testOpParam.reduceType = HcclReduceOp::HCCL_REDUCE_SUM;
    testOpParam.devtype = DevType::DEV_TYPE_910_93;
    testOpParam.DataDes.count = 800;
    testOpParam.DataDes.dataType = HcclDataType::HCCL_DATA_TYPE_INT32;
    testOpParam.algName = "AllReduceDoubleRingConcurrentExecutor";
    Checker checker;
    HcclResult ret;
    ret = checker.Check(testOpParam, ranktable, topoMeta);
    EXPECT_EQ(ret, HcclResult::HCCL_SUCCESS);
}

TEST_F(AllReduceTest, allreduce_310P3_opbase_AllReduceRing)
{
    RankTable_t ranktable;
    RankTable_For_LLT gen;
    TopoMeta topoMeta;
    gen.GenTopoMeta(topoMeta, 1, 1, 8);
    gen.GenRankTable(topoMeta, ranktable);

    TestOpParam testOpParam;
    testOpParam.opType = HcclCMDType::HCCL_CMD_ALLREDUCE;
    testOpParam.tag = "AllReduce";
    testOpParam.opMode = OPBASE;
    testOpParam.devtype = DevType::DEV_TYPE_310P3;
    testOpParam.DataDes.count = 100;
    testOpParam.DataDes.dataType = HcclDataType::HCCL_DATA_TYPE_INT32;
    testOpParam.reduceType = HcclReduceOp::HCCL_REDUCE_SUM;
    testOpParam.algName = "AllReduceRing";

    Checker checker;
    HcclResult ret;
    ret = checker.Check(testOpParam, ranktable, topoMeta);
    EXPECT_EQ(ret, HcclResult::HCCL_SUCCESS);
}

TEST_F(AllReduceTest, allreduce_910_93_opbase_AllReduceFastDoubleRingFor91093Executor_superPod)
{
    RankTable_t ranktable;
    RankTable_For_LLT gen;
    TopoMeta topoMeta;
    gen.GenTopoMeta(topoMeta, 2, 1, 8);
    gen.GenRankTable(topoMeta, ranktable);
 
    TestOpParam testOpParam;
    testOpParam.opType = HcclCMDType::HCCL_CMD_ALLREDUCE;
    testOpParam.tag = "AllReduce";
    testOpParam.opMode = OPBASE;
    testOpParam.reduceType = HcclReduceOp::HCCL_REDUCE_SUM;
    testOpParam.devtype = DevType::DEV_TYPE_910_93;
    testOpParam.DataDes.count = 800;
    testOpParam.DataDes.dataType = HcclDataType::HCCL_DATA_TYPE_INT32;
    testOpParam.algName = "AllReduceFastDoubleRingFor91093Executor";
    Checker checker;
    HcclResult ret;
    ret = checker.Check(testOpParam, ranktable, topoMeta);
    EXPECT_EQ(ret, HcclResult::HCCL_SUCCESS);
}

TEST_F(AllReduceTest, allreduce_910_93_level1_NB)
{
    RankTable_t ranktable;
    RankTable_For_LLT gen;
    TopoMeta topoMeta;
    gen.GenTopoMeta(topoMeta, 2, 1, 8);
    gen.GenRankTable(topoMeta, ranktable);
 
    setenv("HCCL_ALGO", "level0:ring;level1:NB", 1);

    TestOpParam testOpParam;
    testOpParam.opType = HcclCMDType::HCCL_CMD_ALLREDUCE;
    testOpParam.tag = "AllReduce";
    testOpParam.opMode = OPBASE;
    testOpParam.reduceType = HcclReduceOp::HCCL_REDUCE_SUM;
    testOpParam.devtype = DevType::DEV_TYPE_910_93;
    testOpParam.DataDes.count = 800;
    testOpParam.DataDes.dataType = HcclDataType::HCCL_DATA_TYPE_INT32;
    testOpParam.algName = "AllReduceRingFor91093Executor";
    Checker checker;
    HcclResult ret;
    ret = checker.Check(testOpParam, ranktable, topoMeta);
    EXPECT_EQ(ret, HcclResult::HCCL_SUCCESS);
}

TEST_F(AllReduceTest, allreduce_910_93_level1_NHR)
{
    RankTable_t ranktable;
    RankTable_For_LLT gen;
    TopoMeta topoMeta;
    gen.GenTopoMeta(topoMeta, 2, 1, 8);
    gen.GenRankTable(topoMeta, ranktable);
 
    setenv("HCCL_ALGO", "level0:ring;level1:NHR", 1);

    TestOpParam testOpParam;
    testOpParam.opType = HcclCMDType::HCCL_CMD_ALLREDUCE;
    testOpParam.tag = "AllReduce";
    testOpParam.opMode = OPBASE;
    testOpParam.reduceType = HcclReduceOp::HCCL_REDUCE_SUM;
    testOpParam.devtype = DevType::DEV_TYPE_910_93;
    testOpParam.DataDes.count = 800;
    testOpParam.DataDes.dataType = HcclDataType::HCCL_DATA_TYPE_INT32;
    testOpParam.algName = "AllReduceRingFor91093Executor";
    Checker checker;
    HcclResult ret;
    ret = checker.Check(testOpParam, ranktable, topoMeta);
    EXPECT_EQ(ret, HcclResult::HCCL_SUCCESS);
}

TEST_F(AllReduceTest, allreduce_910_93_level1_AHC)
{
    RankTable_t ranktable;
    RankTable_For_LLT gen;
    TopoMeta topoMeta;
    gen.GenTopoMeta(topoMeta, 2, 1, 8);
    gen.GenRankTable(topoMeta, ranktable);
 
    setenv("HCCL_ALGO", "level0:ring;level1:AHC", 1);

    TestOpParam testOpParam;
    testOpParam.opType = HcclCMDType::HCCL_CMD_ALLREDUCE;
    testOpParam.tag = "AllReduce";
    testOpParam.opMode = OPBASE;
    testOpParam.reduceType = HcclReduceOp::HCCL_REDUCE_SUM;
    testOpParam.devtype = DevType::DEV_TYPE_910_93;
    testOpParam.DataDes.count = 800;
    testOpParam.DataDes.dataType = HcclDataType::HCCL_DATA_TYPE_INT32;
    testOpParam.algName = "AllReduceRingFor91093Executor";
    Checker checker;
    HcclResult ret;
    ret = checker.Check(testOpParam, ranktable, topoMeta);
    EXPECT_EQ(ret, HcclResult::HCCL_SUCCESS);
}

TEST_F(AllReduceTest, allreduce_310P3_offload_AllReduceRing)
{
    RankTable_t ranktable;
    RankTable_For_LLT gen;
    TopoMeta topoMeta;
    gen.GenTopoMeta(topoMeta, 1, 1, 8);
    gen.GenRankTable(topoMeta, ranktable);

    TestOpParam testOpParam;
    testOpParam.opType = HcclCMDType::HCCL_CMD_ALLREDUCE;
    testOpParam.tag = "AllReduce";
    testOpParam.opMode = OFFLOAD;
    testOpParam.devtype = DevType::DEV_TYPE_310P3;
    testOpParam.DataDes.count = 100;
    testOpParam.DataDes.dataType = HcclDataType::HCCL_DATA_TYPE_INT32;
    testOpParam.reduceType = HcclReduceOp::HCCL_REDUCE_SUM;
    testOpParam.algName = "AllReduceRing";

    Checker checker;
    HcclResult ret;
    ret = checker.Check(testOpParam, ranktable, topoMeta);
    EXPECT_EQ(ret, HcclResult::HCCL_SUCCESS);
}

TEST_F(AllReduceTest, allreduce_310P3V_opbase_AllReduceRing)
{
    RankTable_t ranktable;
    RankTable_For_LLT gen;
    TopoMeta topoMeta;
    gen.GenTopoMeta(topoMeta, 1, 1, 8);
    gen.GenRankTable(topoMeta, ranktable);

    TestOpParam testOpParam;
    testOpParam.opType = HcclCMDType::HCCL_CMD_ALLREDUCE;
    testOpParam.tag = "AllReduce";
    testOpParam.opMode = OPBASE;
    testOpParam.devtype = DevType::DEV_TYPE_310P3;
    testOpParam.DataDes.count = 100;
    testOpParam.DataDes.dataType = HcclDataType::HCCL_DATA_TYPE_INT32;
    testOpParam.reduceType = HcclReduceOp::HCCL_REDUCE_SUM;
    testOpParam.algName = "AllReduceRing";
    testOpParam.is310P3V = true;

    Checker checker;
    HcclResult ret;
    ret = checker.Check(testOpParam, ranktable, topoMeta);
    EXPECT_EQ(ret, HcclResult::HCCL_SUCCESS);
}

TEST_F(AllReduceTest, allreduce_310P3V_offload_AllReduceRing)
{
    RankTable_t ranktable;
    RankTable_For_LLT gen;
    TopoMeta topoMeta;
    gen.GenTopoMeta(topoMeta, 1, 1, 8);
    gen.GenRankTable(topoMeta, ranktable);

    TestOpParam testOpParam;
    testOpParam.opType = HcclCMDType::HCCL_CMD_ALLREDUCE;
    testOpParam.tag = "AllReduce";
    testOpParam.opMode = OFFLOAD;
    testOpParam.devtype = DevType::DEV_TYPE_310P3;
    testOpParam.DataDes.count = 100;
    testOpParam.DataDes.dataType = HcclDataType::HCCL_DATA_TYPE_INT32;
    testOpParam.reduceType = HcclReduceOp::HCCL_REDUCE_SUM;
    testOpParam.algName = "AllReduceRing";
    testOpParam.is310P3V = true;

    Checker checker;
    HcclResult ret;
    ret = checker.Check(testOpParam, ranktable, topoMeta);
    EXPECT_EQ(ret, HcclResult::HCCL_SUCCESS);
}

TEST_F(AllReduceTest, allreduce_910_93_retry_inplace_presync_case_level0)
{
    RankTable_t ranktable;
    RankTable_For_LLT gen;
    TopoMeta topoMeta;
    gen.GenTopoMeta(topoMeta, 1, 1, 16);
    gen.GenRankTable(topoMeta, ranktable);

    TestOpParam testOpParam;
    testOpParam.opType = HcclCMDType::HCCL_CMD_ALLREDUCE;
    testOpParam.tag = "AllReduce";
    testOpParam.opMode = OPBASE;
    testOpParam.devtype = DevType::DEV_TYPE_910_93;
    testOpParam.DataDes.count = 134217728;
    testOpParam.DataDes.dataType = HcclDataType::HCCL_DATA_TYPE_FP32;
    testOpParam.reduceType = HcclReduceOp::HCCL_REDUCE_SUM;
    testOpParam.algName = "AlignedAllReduceDoubleRingFor91093Executor";
    testOpParam.algOpContext.opRetryHandler.isInplacePreSync = true;

    Checker checker;
    HcclResult ret;
    ret = checker.Check(testOpParam, ranktable, topoMeta);
    // PreSync会memcopy一段无效数据以占满所有端口，从而达到检测断链的效果，所以数据本身没有被使用，是允许的。
    // 且PreSync不执行任何reduce scatter算法。
}

TEST_F(AllReduceTest, allreduce_910_93_retry_inplace_presync_case_level1)
{
    RankTable_t ranktable;
    RankTable_For_LLT gen;
    TopoMeta topoMeta;
    gen.GenTopoMeta(topoMeta, 1, 8, 1);
    gen.GenRankTable(topoMeta, ranktable);

    TestOpParam testOpParam;
    testOpParam.opType = HcclCMDType::HCCL_CMD_ALLREDUCE;
    testOpParam.tag = "AllReduce";
    testOpParam.opMode = OPBASE;
    testOpParam.devtype = DevType::DEV_TYPE_910_93;
    testOpParam.DataDes.count = 134217728;
    testOpParam.DataDes.dataType = HcclDataType::HCCL_DATA_TYPE_FP32;
    testOpParam.reduceType = HcclReduceOp::HCCL_REDUCE_SUM;
    testOpParam.algName = "AlignedAllReduceDoubleRingFor91093Executor";
    testOpParam.algOpContext.opRetryHandler.isInplacePreSync = true;

    Checker checker;
    HcclResult ret;
    ret = checker.Check(testOpParam, ranktable, topoMeta);
    // PreSync会memcopy一段无效数据以占满所有端口，从而达到检测断链的效果，所以数据本身没有被使用，是允许的。
    // 且PreSync不执行任何reduce scatter算法。
}

TEST_F(AllReduceTest, allreduce_910_93_retry_inplace_presync_case_level2)
{
    RankTable_t ranktable;
    RankTable_For_LLT gen;
    TopoMeta topoMeta;
    gen.GenTopoMeta(topoMeta, 2, 1, 1);
    gen.GenRankTable(topoMeta, ranktable);

    TestOpParam testOpParam;
    testOpParam.opType = HcclCMDType::HCCL_CMD_ALLREDUCE;
    testOpParam.tag = "AllReduce";
    testOpParam.opMode = OPBASE;
    testOpParam.devtype = DevType::DEV_TYPE_910_93;
    testOpParam.DataDes.count = 134217728;
    testOpParam.DataDes.dataType = HcclDataType::HCCL_DATA_TYPE_FP32;
    testOpParam.reduceType = HcclReduceOp::HCCL_REDUCE_SUM;
    testOpParam.algName = "AlignedAllReduceDoubleRingFor91093Executor";
    testOpParam.algOpContext.opRetryHandler.isInplacePreSync = true;

    Checker checker;
    HcclResult ret;
    ret = checker.Check(testOpParam, ranktable, topoMeta);
    // PreSync会memcopy一段无效数据以占满所有端口，从而达到检测断链的效果，所以数据本身没有被使用，是允许的。
    // 且PreSync不执行任何reduce scatter算法。
}

TEST_F(AllReduceTest, all_reduce_smallcount_multiserver_test)
{
    RankTable_t ranktable;
    RankTable_For_LLT gen;
    TopoMeta topoMeta;
    gen.GenTopoMeta(topoMeta, 1, 2, 4);
    gen.GenRankTable(topoMeta, ranktable);

    TestOpParam testOpParam;
    testOpParam.opType = HcclCMDType::HCCL_CMD_ALLREDUCE;
    testOpParam.tag = "AllReduce";
    testOpParam.opMode = OFFLOAD;

    testOpParam.DataDes.count = 100;
    testOpParam.DataDes.dataType = HcclDataType::HCCL_DATA_TYPE_INT8;
    testOpParam.devtype = DevType::DEV_TYPE_910_93;
    testOpParam.reduceType = HcclReduceOp::HCCL_REDUCE_SUM;
    Checker checker;
    HcclResult ret;
    ret = checker.Check(testOpParam, ranktable, topoMeta);

    EXPECT_EQ(ret, HcclResult::HCCL_SUCCESS);
}

TEST_F(AllReduceTest, allreduce_ax_4server_16p)
{
    RankTable_t ranktable;
    RankTable_For_LLT gen;
    TopoMeta topoMeta;
    gen.GenTopoMeta(topoMeta, 1, 4, 16);
    gen.GenRankTable(topoMeta, ranktable);

    TestOpParam testOpParam;
    testOpParam.opType = HcclCMDType::HCCL_CMD_ALLREDUCE;
    testOpParam.tag = "AllReduce";
    testOpParam.opMode = OPBASE;
    testOpParam.DataDes.count = 100;
    testOpParam.DataDes.dataType = HcclDataType::HCCL_DATA_TYPE_INT8;
    testOpParam.devtype = DevType::DEV_TYPE_910B;
    testOpParam.reduceType = HcclReduceOp::HCCL_REDUCE_SUM;

    Checker checker;
    HcclResult ret;
    checker.CloseRankMemCheck();
    ret = checker.Check(testOpParam, ranktable, topoMeta);
    EXPECT_EQ(ret, HcclResult::HCCL_SUCCESS);
}

TEST_F(AllReduceTest, allreduce_mix_AllReduceMixExecutor)
{
    RankTable_t ranktable;
    RankTable_For_LLT gen;

    /***** GenTopoMeta Start *****/
    TopoMeta topoMeta;
    SuperPodMeta superPodMeta;
    ServerMeta serverMeta910B;
    u32 rankNum910B = 16;
    for (u32 k = 0; k < rankNum910B; k++) {
        serverMeta910B.push_back(k);
    }
    superPodMeta.push_back(serverMeta910B);
    ServerMeta serverMeta91093;
    u32 rankNum91093 = 16;
    for (u32 k = 0; k < rankNum91093; k++) {
        serverMeta91093.push_back(k);
    }
    superPodMeta.push_back(serverMeta91093);

    topoMeta.push_back(superPodMeta);
    /***** GenTopoMeta End *****/

    /***** GenRankTable Start *****/
    gen.GenRankTable(topoMeta, ranktable);
    for (auto &rankInfo : ranktable.rankList) {
        if (rankInfo.serverIdx == 0) {
            rankInfo.deviceInfo.deviceType = DevType::DEV_TYPE_910B;
        } else {
            rankInfo.deviceInfo.deviceType = DevType::DEV_TYPE_910_93;
        }
    }
    /***** GenRankTable End *****/

    TestOpParam testOpParam;
    testOpParam.opType = HcclCMDType::HCCL_CMD_ALLREDUCE;
    testOpParam.tag = "AllReduce";
    testOpParam.opMode = OPBASE;
    testOpParam.DataDes.count = 100;
    testOpParam.DataDes.dataType = HcclDataType::HCCL_DATA_TYPE_INT8;
    testOpParam.reduceType = HcclReduceOp::HCCL_REDUCE_SUM;
    testOpParam.devTypes.insert(DevType::DEV_TYPE_910B);
    testOpParam.devTypes.insert(DevType::DEV_TYPE_910_93);

    Checker checker;
    HcclResult ret;
    checker.CloseRankMemCheck();
    ret = checker.Check(testOpParam, ranktable, topoMeta);
    EXPECT_EQ(ret, HcclResult::HCCL_SUCCESS);
}

TEST_F(AllReduceTest, allreduce_mix_AllReduceMixExecutor_deter)
{
    setenv("HCCL_DETERMINISTIC", "true", 1);
    RankTable_t ranktable;
    RankTable_For_LLT gen;

    /***** GenTopoMeta Start *****/
    TopoMeta topoMeta;
    SuperPodMeta superPodMeta;
    ServerMeta serverMeta910B;
    u32 rankNum910B = 16;
    for (u32 k = 0; k < rankNum910B; k++) {
        serverMeta910B.push_back(k);
    }
    superPodMeta.push_back(serverMeta910B);
    ServerMeta serverMeta91093;
    u32 rankNum91093 = 16;
    for (u32 k = 0; k < rankNum91093; k++) {
        serverMeta91093.push_back(k);
    }
    superPodMeta.push_back(serverMeta91093);

    topoMeta.push_back(superPodMeta);
    /***** GenTopoMeta End *****/

    /***** GenRankTable Start *****/
    gen.GenRankTable(topoMeta, ranktable);
    for (auto &rankInfo : ranktable.rankList) {
        if (rankInfo.serverIdx == 0) {
            rankInfo.deviceInfo.deviceType = DevType::DEV_TYPE_910B;
        } else {
            rankInfo.deviceInfo.deviceType = DevType::DEV_TYPE_910_93;
        }
    }
    /***** GenRankTable End *****/

    TestOpParam testOpParam;
    testOpParam.opType = HcclCMDType::HCCL_CMD_ALLREDUCE;
    testOpParam.tag = "AllReduce";
    testOpParam.opMode = OPBASE;
    testOpParam.DataDes.count = 100;
    testOpParam.DataDes.dataType = HcclDataType::HCCL_DATA_TYPE_FP32;
    testOpParam.reduceType = HcclReduceOp::HCCL_REDUCE_SUM;
    testOpParam.devTypes.insert(DevType::DEV_TYPE_910B);
    testOpParam.devTypes.insert(DevType::DEV_TYPE_910_93);

    Checker checker;
    HcclResult ret;
    ret = checker.Check(testOpParam, ranktable, topoMeta);
    EXPECT_EQ(ret, HcclResult::HCCL_SUCCESS);
}

TEST_F(AllReduceTest, allreduce_mix_AllReduceMixExecutor_deter_comm)
{
    setenv("HCCL_DETERMINISTIC", "true", 1);
    RankTable_t ranktable;
    RankTable_For_LLT gen;

    /***** GenTopoMeta Start *****/
    TopoMeta topoMeta;
    SuperPodMeta superPodMeta;
    ServerMeta serverMeta910B;
    u32 rankNum910B = 1;
    for (u32 k = 0; k < rankNum910B; k++) {
        serverMeta910B.push_back(k);
    }
    superPodMeta.push_back(serverMeta910B);
    ServerMeta serverMeta91093;
    u32 rankNum91093 = 1;
    for (u32 k = 0; k < rankNum91093; k++) {
        serverMeta91093.push_back(k);
    }
    superPodMeta.push_back(serverMeta91093);

    topoMeta.push_back(superPodMeta);
    /***** GenTopoMeta End *****/

    /***** GenRankTable Start *****/
    gen.GenRankTable(topoMeta, ranktable);
    for (auto &rankInfo : ranktable.rankList) {
        if (rankInfo.serverIdx == 0) {
            rankInfo.deviceInfo.deviceType = DevType::DEV_TYPE_910B;
        } else {
            rankInfo.deviceInfo.deviceType = DevType::DEV_TYPE_910_93;
        }
    }
    /***** GenRankTable End *****/

    TestOpParam testOpParam;
    testOpParam.opType = HcclCMDType::HCCL_CMD_ALLREDUCE;
    testOpParam.tag = "AllReduce";
    testOpParam.opMode = OPBASE;
    testOpParam.DataDes.count = 100;
    testOpParam.DataDes.dataType = HcclDataType::HCCL_DATA_TYPE_FP32;
    testOpParam.reduceType = HcclReduceOp::HCCL_REDUCE_SUM;
    testOpParam.devTypes.insert(DevType::DEV_TYPE_910B);
    testOpParam.devTypes.insert(DevType::DEV_TYPE_910_93);

    Checker checker;
    HcclResult ret;
    ret = checker.Check(testOpParam, ranktable, topoMeta);
    EXPECT_EQ(ret, HcclResult::HCCL_SUCCESS);
}

TEST_F(AllReduceTest, allreduce_aiv_a3_AllReduceMeshAivExecutor)
{
    MOCKER(GetExternalInputHcclAivMode).stubs().will(returnValue(true));

    RankTable_t ranktable;
    RankTable_For_LLT gen;
    TopoMeta topoMeta;
    gen.GenTopoMeta(topoMeta, 1, 1, 16);
    gen.GenRankTable(topoMeta, ranktable);

    TestOpParam testOpParam;
    testOpParam.opType = HcclCMDType::HCCL_CMD_ALLREDUCE;
    testOpParam.tag = "AllReduce";
    testOpParam.opMode = OPBASE;
    testOpParam.DataDes.count = 100;
    testOpParam.DataDes.dataType = HcclDataType::HCCL_DATA_TYPE_INT8;
    testOpParam.devtype = DevType::DEV_TYPE_910_93;
    testOpParam.reduceType = HcclReduceOp::HCCL_REDUCE_SUM;
    testOpParam.aicpuUnfoldMode = true;

    Checker checker;
    HcclResult ret;
    ret = checker.Check(testOpParam, ranktable, topoMeta);
    EXPECT_EQ(ret, HcclResult::HCCL_SUCCESS);
}

TEST_F(AllReduceTest, allreduce_AllReduceRingFor91093Executor_NHR)
{
    RankTable_t ranktable;
    RankTable_For_LLT gen;
    TopoMeta topoMeta;
    gen.GenTopoMeta(topoMeta, 2, 2, 8);
    gen.GenRankTable(topoMeta, ranktable);

    setenv("HCCL_ALGO", "level0:NA;level1:NHR;level2:NHR", 1);
    TestOpParam testOpParam;
    testOpParam.opType = HcclCMDType::HCCL_CMD_ALLREDUCE;
    testOpParam.tag = "AllReduce";
    testOpParam.opMode = OPBASE;
    testOpParam.DataDes.count = 100;
    testOpParam.DataDes.dataType = HcclDataType::HCCL_DATA_TYPE_INT8;
    testOpParam.devtype = DevType::DEV_TYPE_910_93;
    testOpParam.reduceType = HcclReduceOp::HCCL_REDUCE_SUM;
    testOpParam.algName = "AllReduceRingFor91093Executor";

    Checker checker;
    HcclResult ret;
    ret = checker.Check(testOpParam, ranktable, topoMeta);
    EXPECT_EQ(ret, HcclResult::HCCL_SUCCESS);
}

TEST_F(AllReduceTest, allreduce_AllReduceRingFor91093Executor_NB)
{
    RankTable_t ranktable;
    RankTable_For_LLT gen;
    TopoMeta topoMeta;
    gen.GenTopoMeta(topoMeta, 2, 2, 8);
    gen.GenRankTable(topoMeta, ranktable);

    setenv("HCCL_ALGO", "level0:NA;level1:NB;level2:NB", 1);
    TestOpParam testOpParam;
    testOpParam.opType = HcclCMDType::HCCL_CMD_ALLREDUCE;
    testOpParam.tag = "AllReduce";
    testOpParam.opMode = OPBASE;
    testOpParam.DataDes.count = 100;
    testOpParam.DataDes.dataType = HcclDataType::HCCL_DATA_TYPE_INT8;
    testOpParam.devtype = DevType::DEV_TYPE_910_93;
    testOpParam.reduceType = HcclReduceOp::HCCL_REDUCE_SUM;
    testOpParam.algName = "AllReduceRingFor91093Executor";

    Checker checker;
    HcclResult ret;
    ret = checker.Check(testOpParam, ranktable, topoMeta);
    EXPECT_EQ(ret, HcclResult::HCCL_SUCCESS);
}

TEST_F(AllReduceTest, allreduce_AllReduceRingFor91093Executor_Ring)
{
    RankTable_t ranktable;
    RankTable_For_LLT gen;
    TopoMeta topoMeta;
    gen.GenTopoMeta(topoMeta, 2, 2, 2);
    gen.GenRankTable(topoMeta, ranktable);

    setenv("HCCL_ALGO", "level0:NA;level1:ring;level2:ring", 1);
    TestOpParam testOpParam;
    testOpParam.opType = HcclCMDType::HCCL_CMD_ALLREDUCE;
    testOpParam.tag = "AllReduce";
    testOpParam.opMode = OPBASE;
    testOpParam.DataDes.count = 100;
    testOpParam.DataDes.dataType = HcclDataType::HCCL_DATA_TYPE_INT8;
    testOpParam.devtype = DevType::DEV_TYPE_910_93;
    testOpParam.reduceType = HcclReduceOp::HCCL_REDUCE_SUM;
    testOpParam.algName = "AllReduceRingFor91093Executor";

    Checker checker;
    HcclResult ret;
    ret = checker.Check(testOpParam, ranktable, topoMeta);
    EXPECT_EQ(ret, HcclResult::HCCL_SUCCESS);
}

TEST_F(AllReduceTest, allreduce_aiv_ax_AllReduceSmallCountAivRdmaExecutor)
{
    MOCKER(GetExternalInputHcclAivMode).stubs().will(returnValue(true));
    MOCKER(HcclD2DMemcpyAsync).stubs().with(any()).will(returnValue(HCCL_SUCCESS));

    RankTable_t ranktable;
    RankTable_For_LLT gen;
    TopoMeta topoMeta;
    gen.GenTopoMeta(topoMeta, 1, 1, 16);
    gen.GenRankTable(topoMeta, ranktable);

    TestOpParam testOpParam;
    testOpParam.opType = HcclCMDType::HCCL_CMD_ALLREDUCE;
    testOpParam.tag = "AllReduce";
    testOpParam.opMode = OPBASE;
    testOpParam.DataDes.count = 100;
    testOpParam.DataDes.dataType = HcclDataType::HCCL_DATA_TYPE_INT8;
    testOpParam.devtype = DevType::DEV_TYPE_910B;
    testOpParam.reduceType = HcclReduceOp::HCCL_REDUCE_SUM;
    testOpParam.algName = "AllReduceSmallCountAivRdmaExecutor";

    Checker checker;
    HcclResult ret;
    ret = checker.Check(testOpParam, ranktable, topoMeta);
}

TEST_F(AllReduceTest, allreduce_A3_2Server1Rank_nb_test)
{
    RankTable_t ranktable;
    RankTable_For_LLT gen;
    TopoMeta topoMeta;
    gen.GenTopoMeta(topoMeta, 1, 2, 1);
    gen.GenRankTable(topoMeta, ranktable);

    setenv("HCCL_ALGO", "level0:NA;level1:NB", 1);
    TestOpParam testOpParam;
    testOpParam.opType = HcclCMDType::HCCL_CMD_ALLREDUCE;
    testOpParam.tag = "AllReduce";
    testOpParam.opMode = OFFLOAD;
    testOpParam.DataDes.count = 100;
    testOpParam.DataDes.dataType = HcclDataType::HCCL_DATA_TYPE_INT8;
    testOpParam.reduceType = HcclReduceOp::HCCL_REDUCE_SUM;
    testOpParam.devtype = DevType::DEV_TYPE_910_93;

    Checker checker;
    HcclResult ret;
    ret = checker.Check(testOpParam, ranktable, topoMeta);
    EXPECT_EQ(ret, HcclResult::HCCL_SUCCESS);
}